<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>

    <style>

    </style>
</head>

<body>

    <div id="box">


    </div>


    <script src="./js/react.js"></script>
    <script src="./js/react-dom.js"></script>
    <script src="./js/babel.min.js"></script>
    <script src="./js/prop-types.js"></script>

    <script type="text/babel">

        //  组件名.propTypes;

        
        // 1、函数式组件
        function Book(props) {
            return (
                <div>
                    <p>书名：{props.name}</p>
                    <p>价格：{props.price}</p>
                    <p>作者：{props.author}</p>
                </div>
            )
        }

        Book.defaultProps = {
            name:"如何少奋斗二十年"
        }

        Book.propTypes={
            name:PropTypes.string,
            price:PropTypes.number,
            author:PropTypes.string.isRequired
        }
        

        // 2、类组件：
        /*
        class Book extends React.Component{
            render(){
                return (
                    <div>
                        <p>书名：{this.props.name}</p>
                    </div>
                )
            }
        }

        Book.defaultProps = {
            name:"如何少奋斗二十年"
        }
        */


        const root = (<div>
            <h1>组件：</h1>
            <Book name="如何让富婆爱上我" price={12.5} author="陈正伟" />
            <Book  price={31.2} author="高玉贵" />
        </div>);

        ReactDOM.render(root, document.getElementById("box"));


    </script>
</body>

</html>